package org.hyf.inspur.LessonDesin.clear.count8;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

import java.io.IOException;

public class PreUsersMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        try {
            //创建配置信息
            Configuration conf = new Configuration();
            //map内存设置
            conf.set("mapreduce.map.memory.mb", "5120");
            conf.set("mapreduce.reduce.memory.mb", "5120");
            String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
            // 创建任务
            Job job = new Job(conf, "UserPortraitMain");
            // 打成jar包运行，这句话是关键
            job.setJarByClass(PreUsersMain.class);
            // 自定义Mapper类和设置map函数输出数据的key和value的类型
            job.setMapperClass(PreUsersMapper.class);
            job.setReducerClass(PreUsersReducer.class);
            //设置map输出的key类型
            job.setMapOutputKeyClass(Text.class);
            //设置map输出的value类型
            job.setMapOutputValueClass(IntWritable.class);
            //设置输出的key类型
            job.setOutputKeyClass(NullWritable.class);
            //设置输出的value类型
            job.setOutputValueClass(Text.class);
            // 分组函数
            //job.setPartitionerClass(KeyPartitioner.class);
            // 分组函数
            //job.setGroupingComparatorClass(KeyGroupingComparator.class);
            //输入输出路径
            FileInputFormat.addInputPaths(job, "d://data/output/output/part-m-00*");
            FileOutputFormat.setOutputPath(job, new Path("d://data/output/output9"));
            //提交作业 判断退出条件（0正常退出，1非正常退出）
            System.exit(job.waitForCompletion(true) ? 0 : 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
